package com.xzj.admin.analysis.base.custom.it;

import com.alibaba.fastjson2.JSONObject;
import com.xzj.admin.analysis.base.common.handle.ThemeSpecialAnalysisHandle;
import com.xzj.admin.analysis.base.custom.common.PlatformSpecialHandle;
import com.xzj.admin.analysis.base.domain.ResMessageManage;
import com.xzj.admin.analysis.base.domain.CommonFlowInfo;

/**
 * @program: xzj-admin
 * @ClassName: VcThemeSpecialAnalysisHandle
 * @description: IT-VC特殊主题处理器
 * @author: XiaZunJun
 * @create: 2024-11-20 14:23
 */
public class VcThemeSpecialAnalysisHandle extends ThemeSpecialAnalysisHandle {

    static {
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.region.name(), MESSAGE_TAG.add.name()), PlatformSpecialHandle::regionAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.region.name(), MESSAGE_TAG.edit.name()), PlatformSpecialHandle::regionAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.datacenter.name(), MESSAGE_TAG.add.name()), PlatformSpecialHandle::datacenterAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.datacenter.name(), MESSAGE_TAG.edit.name()), PlatformSpecialHandle::datacenterAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.host.name(), MESSAGE_TAG.add.name()), PlatformSpecialHandle::vmOrHostAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.host.name(), MESSAGE_TAG.edit.name()), PlatformSpecialHandle::vmOrHostAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.vm.name(), MESSAGE_TAG.add.name()), PlatformSpecialHandle::vmOrHostAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.vm.name(), MESSAGE_TAG.edit.name()), PlatformSpecialHandle::vmOrHostAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.network.name(), MESSAGE_TAG.add.name()), VcThemeSpecialAnalysisHandle::networkAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.network.name(), MESSAGE_TAG.edit.name()), VcThemeSpecialAnalysisHandle::networkAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.vSwitch.name(), MESSAGE_TAG.add.name()), VcThemeSpecialAnalysisHandle::vSwitchAdd);
        putThemeSpecialHandle(buildKey(RESOURCE_TYPE.vSwitch.name(), MESSAGE_TAG.edit.name()), VcThemeSpecialAnalysisHandle::vSwitchAdd);
    }

    public VcThemeSpecialAnalysisHandle(String cloudId, String cloudType) {
        super(cloudId, cloudType, message ->
                RESOURCE_TYPE.host.equals(message.getMessageSource())
                        || RESOURCE_TYPE.vm.equals(message.getMessageSource())
                        || RESOURCE_TYPE.datacenter.equals(message.getMessageSource())
                        || RESOURCE_TYPE.region.equals(message.getMessageSource())
                        || RESOURCE_TYPE.network.equals(message.getMessageSource())
                        || RESOURCE_TYPE.vSwitch.equals(message.getMessageSource())
        );
    }

    private static void networkAdd(ResMessageManage message, CommonFlowInfo info){
        JSONObject row = message.getRowData();
        row.put("switchType","network");
        message.setMessageJson(row.toJSONString());
    }
    private static void vSwitchAdd(ResMessageManage message, CommonFlowInfo info){
        JSONObject row = message.getRowData();
        row.put("switchType","vSwitch");
        message.setMessageJson(row.toJSONString());
    }
}
